package com.ruoyi.web.controller.counter;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Signin;
import com.ruoyi.counter.service.ISigninService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 登录记录Controller
 *
 * @author xll
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/counter/signin")
public class SigninController extends BaseController
{
    @Autowired
    private ISigninService signinService;

    /**
     * 查询登录记录列表
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:list')")
    @GetMapping("/list")
    public TableDataInfo list(Signin signin)
    {
        System.out.println(signin.toString());
        startPage();
        List<Signin> list = signinService.selectSigninList(signin);
        return getDataTable(list);
    }

    /**
     * 导出登录记录列表
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:export')")
    @Log(title = "登录记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Signin signin)
    {
        List<Signin> list = signinService.selectSigninList(signin);
        ExcelUtil<Signin> util = new ExcelUtil<Signin>(Signin.class);
        return util.exportExcel(list, "登录记录数据");
    }

    /**
     * 获取登录记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(signinService.selectSigninById(id));
    }

    /**
     * 新增登录记录
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:add')")
    @Log(title = "登录记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Signin signin)
    {
        return toAjax(signinService.insertSignin(signin));
    }

    /**
     * 修改登录记录
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:edit')")
    @Log(title = "登录记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Signin signin)
    {
        return toAjax(signinService.updateSignin(signin));
    }

    /**
     * 删除登录记录
     */
    @PreAuthorize("@ss.hasPermi('counter:signin:remove')")
    @Log(title = "登录记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(signinService.deleteSigninByIds(ids));
    }
}
